package Utils
import java.util._
/**
  * Created by hunter.coder 涛哥  
  * 2019/2/11 11:45
  * 交流qq:657270652
  * Version: 1.0
  * 更多学习资料：https://blog.csdn.net/coderblack/
  * Description:
  **/
object DelayUtil {

  val random = new Random()

  // 秒级别延迟
  def delaySeconds(factor:Double = 1): Long ={
    val num = random.nextInt(60)
    val d = random.nextGaussian()+0.1  // 保证最低100毫秒的延迟
    (Math.abs(d)*1000L*num*factor).asInstanceOf[Long]
  }

  // 分钟级别延迟
  def delayMinutes(factor:Double = 1): Long ={
    val num = random.nextInt(10)  // 10分钟内的延迟
    val d = random.nextGaussian()+0.1
    (Math.abs(d)*num*factor*60*1000L).asInstanceOf[Long]
  }


  // 小时级别延迟
  def delayHours(factor:Double = 1): Long ={
    val num = random.nextInt(10)  // 10小时内的延迟
    val d = random.nextGaussian()+0.1
    (Math.abs(d)*num*factor*60*60*1500L).asInstanceOf[Long]
  }

  def main(args: Array[String]): Unit = {
    while(true){
      //println((delayMinutes() / 1000D )+ " 秒")
      println((delayMinutes() / (1000*60D) )+ " 分")
      //println((delayHours()/(60*1000*60d))+" 小时")
      Thread.sleep(1000)
    }
  }




}
